<template>
  <div class="approval-order" v-loading.fullscreen.lock="loading">
    <el-form size="medium" label-position="top">
      <el-form-item :label="data.status===0?'拒绝原因':'同意原因'">
        <sys-area-input v-model="remark" :rows="8"></sys-area-input>
      </el-form-item>
    </el-form>

    <div style="text-align:center">
      <el-button size="medium" type="primary" @click="ensure">确定</el-button>
    </div>
  </div>
</template>

<script>
  import SysAreaInput from 'commonComponents/sysAreaInput';

  import OrderMgrApi from 'services/orderMgrApi';

  export default {
    props: {
      data: {
        type: Object,
        required: true
      }
    },

    data() {
      return {
        loading: false,
        remark: ''
      };
    },

    methods: {
      ensure() {
        let remark = this.remark;
        let status = this.data.status;
        if (status === 0 && remark.trim() === '') {
          this.$message('请输入拒绝原因');
          return;
        }

        let order = this.data.order;
        this.loading = true;
        OrderMgrApi.updateRefundOrderStatus({
          orderRefuseApplyId: order.orderRefuseApplyId,
          auditRemark: remark,
          status
        }).then(() => {
          this.loading = false;
          this.$emit('approval-success');
        }).catch(() => {
          this.loading = false;
        });
      }
    },

    components: {
      SysAreaInput
    }
  };

</script>

<style lang="scss" scoped>
  .approval-order {
    padding: 0 10px 10px;
  }

</style>
